<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <style>
        div{
            text-align: center;
        }
    </style>
    <script src="js/jquery.js"></script>
</head>
<body>
<div>
    <h1>核酸检测系统</h1>
    <form action="/list" method="get">
        <select name="nameId">
            <option th:value="0">--请选择--</option>
            <option th:each="name : ${getHosptialName}" th:text="${name.name}" th:value="${name.id}" th:selected="${nameId eq name.id}"></option>
        </select>
        <input type="submit" th:value="查询"/>
        <a href="/SelectAdd"><input type="button" value="新增"/></a>
    </form>

    <table border="1px" style="margin: auto">
        <tr>
            <th>被检测人</th>
            <th>被检测人手机号</th>
            <th>被检测人身份证号</th>
            <th>检测机构</th>
            <th>检测日期</th>
            <th>检测结果</th>
            <th>操作</th>
        </tr>
        <tr th:each="user:${list}">
            <td th:text="${user.assayUser}"></td>
            <td th:text="${user.phone}"></td>
            <td th:text="${user.cardNum}"></td>
            <td th:text="${user.hospital.name}"></td>
            <td th:text="${user.assayTime}"></td>
            <td th:text="${user.assayResult}==0?'检测中':'确诊'"></td>
            <td><a href="#" th:attr="userid=${user.id}, assayresult=${user.assayResult}" onclick="updateTbales(this);">确诊</a></td>
        </tr>
    </table>
</div>
<script>
    function updateTbales(check) {
        var userId = check.getAttribute('userid');
        var assayResult = check.getAttribute('assayresult');

        if (assayResult == 1) {
            alert('该用户已经确诊，不能重复确诊！');
            return;
        }
        var confirmStatus = confirm('请确认该检测者确诊？');
        if (confirmStatus === true) {
            var result = 1;
            window.location.href = '/update?assayResult=' + result + '&id=' + userId;
        }
    }
</script>
</body>
</html>